package com.novelot.plugin.allinone.util;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.UnknownHostException;

public class Logger {
    private static final String TAG = "novelot";

    public static void v(String tag, String msg) {
        System.out.println("\033[32m"+tag + ":" + msg);
    }

    public static void d(String tag, String msg) {
        System.out.println("\033[33m"+tag + ":" + msg);
    }

    public static void i(String tag, String msg) {
        System.out.println("\033[34m"+tag + ":" + msg);
    }

    public static void w(String tag, String msg) {
        System.out.println("\033[35m"+tag + ":" + msg);
    }

    public static void e(String tag, String msg) {
        System.out.println("\033[31m"+tag + ":" + msg);
    }

    public static void v(String msg) {
        v(TAG, msg);
    }

    public static void d(String msg) {
        d(TAG, msg);
    }

    public static void i(String msg) {
        i(TAG, msg);
    }

    public static void w(String msg) {
        w(TAG, msg);
    }

    public static void e(String msg) {
        e(TAG, msg);
    }

    public static String getStackTraceString(Throwable tr) {
        if (tr == null) {
            return "";
        }

        // This is to reduce the amount of log spew that apps do in the non-error
        // condition of the network being unavailable.
        Throwable t = tr;
        while (t != null) {
            if (t instanceof UnknownHostException) {
                return "";
            }
            t = t.getCause();
        }

        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        tr.printStackTrace(pw);
        pw.flush();
        return sw.toString();
    }
}


